package com.example.db.util

import android.content.Context
import androidx.room.Room
import com.example.db.database.AppDataBase

//对外提供统一数据库封装
object RoomUtil {


    private const val dataBaseName = "part.db"
    private lateinit var dataBase:AppDataBase

    //初始化数据
    fun initRoomDataBase(ctx:Context){
        dataBase = Room.databaseBuilder(ctx,AppDataBase::class.java, dataBaseName).build()
    }


    //获取数据
    fun getDataBase():AppDataBase{
        if(dataBase ==null){
            throw RuntimeException("数据库还没有初始化!")
        }
        return dataBase
    }



}